<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文本框</title>
</head>
<body>
    <input type="text"><br>
    <input type="text"><br>
    <input type="text"><br>
    <input type="text"><br>
    <input type="text"><br>
    <input type="text"><br>
    <button id="btn">按钮</button>
    <script>
        // 获取元素
        var txts = document.getElementsByTagName("input");
        // 所有的 input 标签获取焦点点击事件
        for (var i = 0; i < txts.length; i++) {
            txts[i].onclick = function () {
                for (var j = 0 ; j < txts.length ; j++) {
                    txts[j].style.backgroundColor = "white";
                }
                this.style.backgroundColor = "gray";
            };
        }
       
    </script>
</body>
</html>